package com.cenntro.auth.service.impl;

import com.alibaba.fastjson.JSON;
import com.cenntro.auth.mapper.SysPermissionMapper;
import com.cenntro.auth.model.dbo.SysPermissionDO;
import com.cenntro.auth.model.dbo.SysSooidDO;
import com.cenntro.auth.service.SysPermissionService;
import com.cenntro.auth.service.SysSooidService;
import com.cenntro.common.base.BaseServiceImpl;
import com.cenntro.common.common.JPushService;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
/**
 * <p>
 * 角色菜单关联表 服务实现类
 * </p>
 *
 * @author 
 * @since 2019-02-15
 */
@Service
public class SysPermissionServiceImpl extends BaseServiceImpl<SysPermissionMapper> implements SysPermissionService {

	@Resource
	private JPushService JPushService; 
	
	
	@Resource
	private SysSooidService sysSooidService;
	/**
	 * 后台修改用户角色或者修改角色权限以后，通过极光推送 透传最新权限给app端
	 * @param userid 用户id
	 * @190e35f7e0078c89665
	 */
	@Override
	public void refreshPermission(Integer userId) {
		SysSooidDO sooid = sysSooidService.selectById(userId);
		
		List<SysPermissionDO> permList = sysSooidService.selectPermissionByUserId(userId);
		List<String> strPerms = Lists.newArrayList();
		for(SysPermissionDO perm : permList){
			strPerms.add(perm.getUrl());
		}
		Map<String, List<String>> map = Maps.newHashMap();
		map.put("stringPermission", strPerms);
		JPushService.sendMessage(JSON.toJSONString(map), sooid.getRegistrationId());
	}
	
	
	@Override
	public List<SysPermissionDO> selectPermByRoleIds(List<Integer> roleIds) {
		return super.baseMapper.selectPermByRoleIds(roleIds);
	}
}
